package org.example.controller;


import lombok.extern.slf4j.Slf4j;
import org.example.anno.Log;
import org.example.pojo.Emp;
import org.example.pojo.EmpQueryParam;
import org.example.pojo.PageResult;
import org.example.pojo.Result;
import org.example.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/emps")
@Slf4j
public class EmpController{
    @Autowired
    private EmpService empService ;

    /*
    分页查询
     */

    @GetMapping
    public Result list(EmpQueryParam empQueryParam){
        log.info("分页查询参数：{}", empQueryParam);
        PageResult<Emp> pageResult = empService.page(empQueryParam);
        return Result.success(pageResult);
    }


    //新增员工
    @Log
    @PostMapping
    public Result add(@RequestBody Emp emp){
        log.info("新增员工信息：{}", emp);
        empService.save(emp);
        return Result.success();

    }

    //删除
    @Log
    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){
        log.info("删除员工信息：{}", ids);
        empService.deleteByIds(ids);
        return Result.success();
    }

    //查询员工信息
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("根据id查询员工信息：{}", id);
        Emp emp = empService.getById(id);
        return Result.success(emp);
    }

    //修改员工信息
    @Log
    @PutMapping
    public Result update(@RequestBody Emp emp){
        log.info("修改员工信息：{}", emp);
        empService.update(emp);
        return Result.success();
    }
    //查询所有员工信息
    @GetMapping("/list")
    public Result empList(){
        log.info("查询所有员工信息");
        List<Emp> list = empService.list();
        return Result.success(list);
    }
}
